﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace thinger.VisionDemo
{
    public partial class WarnForm : Form
    {
        private Timer updateTimer = new Timer();
        private bool imgI = false;
        private int m = 0;
        private string str;
        public WarnForm(string str)
        {
            InitializeComponent();

            this.updateTimer.Interval = 200;
            this.updateTimer.Tick += UpdateTimer_Tick;
            this.updateTimer.Start();
            this.str = str;
            this.lab.Text = str;

        }
        private void UpdateTimer_Tick(object sender, EventArgs e)
        {

            try
            {
                m++;
                if (imgI)
                {
                    pictureBox1.Image = thinger.VisionDemo.Properties.Resources.jing11;
                }
                else
                {
                    pictureBox1.Image = thinger.VisionDemo.Properties.Resources.jing2;
                }
                imgI = !imgI;

                if (m > 20)
                {
                    this.Close();
                }
            }
            catch (Exception)
            {

            }


        }

        private void WarnForm_Load(object sender, EventArgs e)
        {
            Mainpro.Instance.OnOneWarnRecive += OnOneWarnRecive;
        }

        private void OnOneWarnRecive(object sender, string e)
        {
            if (this.InvokeRequired)
            {
                //this.Invoke(new ImageChanged(Instance_OnImageChanged), sender, e);
                this.Invoke(new Action<object, string>(OnOneWarnRecive), sender, e);
            }
            else
            {
                this.lab.Text = e;
            }
        }

        private void WarnForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (str == "读码失败")
            {
                GlobalVar.Instance.isOpneWarn = false;
                GlobalVar.Instance.isReadWarn = false;
            }

        }

        private void btn_clear_Click(object sender, EventArgs e)
        {

            this.Close();
        }
    }
}
